package HomeWork;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-09-23
 * Time:20:10
 */

import java.util.concurrent.*;

/**
 * 使用ThreadPoolExecutor创建一个忽略最新任务的线程池
 * 作业内容
 * 使用ThreadPoolExecutor创建一个忽略最新任务的线程池，创建规则：
 * 1.核心线程数为5
 * 2.最大线程数为10
 * 3.任务队列为100
 * 4.拒绝策略为忽略最新任务
 */

/**
 *  public ThreadPoolExecutor(int corePoolSize,
 *                               int maximumPoolSize,
 *                               long keepAliveTime,
 *                               TimeUnit unit,
 *                               BlockingQueue<Runnable> workQueue) {
 *         this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
 *              Executors.defaultThreadFactory(), defaultHandler);
 *     }
 */


public class HomeWork920 {
    public static void main(String[] args) {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, //corePoolSize: 核心线程数

                10, //maximumPoolSize: 最大线程数

                3, // keepAliveTime:线程空闲时长

                TimeUnit.SECONDS, // 线程空闲时长的时间单位:秒,要用TimeUnit不能直接写"ms"/"s"

                new LinkedBlockingDeque<>(100), // 任务队列 要new

                new ThreadPoolExecutor.DiscardPolicy()); // 拒绝策略为忽略最新任务 要new
    }
}
